/**
 * author:Administrator
 * date:2016/1/4
 * desc:TODO
 */

'use strict';
var assert = require('assert');
var dao = require('../dao/account.js');
var biz = {};
module.exports = biz;

biz.reset = function*() {
  // TODO
};

biz.create = function*(json) {
  var retObj = yield dao.create(json.name, json.money);
  return {errcode: 0, account: retObj.dataValues};
};

biz.get = function*(id) {
  var retObj = yield dao.findById(id);
  return {errcode: 0, account: retObj.dataValues};
};

biz.update = function*(id, name, money) {
  var kvs = {name: name, money: money};
  var retObj = yield dao.update(id, kvs);
  if (retObj) return {errcode: 0};
  else return {errcode: 1};
};

biz.delete = function*(id) {
  var retObj = yield dao.deleteById(id);
  if (retObj) return {errcode: 0};
  else return {errcode: 1};
};

biz.transaction = function*(from, to, money) {
  var retObj = yield dao.transaction(from, to, money);
  return retObj;
};